package netbayServlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import netbay.NetbayUtility;
import netbay.TransactionManager;
import netbay.UserManager;
import util.jQgrid.JQGridFormatterUtil;

/**
 * Servlet implementation class DeleteAdminServlet
 */
public class DeleteAdminServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteAdminServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    public void init() {
		String configPath = getServletContext().getRealPath(
				"/WEB-INF/config.properties");
		NetbayUtility.init(configPath);
	}
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 request.setCharacterEncoding("UTF-8");
		 response.setContentType("text/json;charset=utf-8");
		 HttpSession session = request.getSession();
		 PrintWriter out = response.getWriter();
	     String strJson = "{}";
	     String rowdata = (String) request.getParameter("rowdata");
		 UserManager um = new UserManager();
		 boolean result = false;
		 String username = um.getUsernameByid(Integer.parseInt(rowdata));
		 result = um.deleteAdmin(rowdata);
		 
		 try {
			 if(result){
				 um.saveLog((String)session.getAttribute("userId"),UserManager.actionDeleteUser,username);
				 strJson = "{\"success\": \"\"}";
			 }
			out.println(strJson);
         } catch (Exception ex) {
             out.println("Error message" + ex.getMessage());
         }
	}

}
